package cn.itcast.mq.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class CommonConfig  {

    @Bean
    public DirectExchange directExchange(){
        //第一个true 表示交换机是否需要持久化
        //第二个false表示交换机是否自动删除持久化的数据   当有队列绑定的时候  ture表示删除  false表示不删除
        return new DirectExchange("simple.direct",true,false);
    }

    @Bean
    public Queue queue(){
        return new Queue("simple.queue",true);
        //return QueueBuilder.durable("simple.queue").build();
    }

    //当消息处理次数达到上线后 放入失败队列  人工干预
    @Bean
    public Binding binding(DirectExchange directExchange,Queue queue){
        return BindingBuilder.bind(queue).to(directExchange).with("simpleKey");
    }
}
